﻿Imports FinanceiroBLL
Imports FinanceiroDAL

Public Class VisualizarFRM
    Public cod As Integer
    Dim objp As New ItensCtasPagarBLL
#Region "Load"
    Private Sub VisualizarFRM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Try
            Carregagrid()
            Me.LBNumRegistros.Text = DGVDados.RowCount.ToString
            Dim totalgrid As Decimal
            TXTTotalGrid.Text = objp.Somaparcelatotal(cod).ToString()
            Decimal.TryParse(TXTTotalGrid.Text.Replace("R$", ""), totalgrid)
            TXTTotalGrid.Text = Math.Round(totalgrid).ToString
            TXTTotalGrid.Text = FormatCurrency(TXTTotalGrid.Text.Replace("R$", "").Replace(" ", ""))
        Catch ex As Exception
        End Try
    End Sub
#End Region
#Region "Carregagrid"
    Sub Carregagrid()
        Dim obj As New ItensCtasPagarBLL
        DGVDados.DataSource = obj.localizar(cod, 2)
        DGVDados.Refresh()
    End Sub
#End Region
#Region "Voltar"
    Private Sub TSBVoltar_Click(sender As System.Object, e As System.EventArgs) Handles TSBVoltar.Click
        Close()
        DGVDados.ClearSelection()
    End Sub
#End Region
#Region "Formata Campo"
    Sub formatacampo()
        Dim vlrtotal As Decimal
        If (Decimal.TryParse(TXTTotalGrid.Text.Replace("R$", ""), vlrtotal)) Then
        Else : vlrtotal = "0,00"
        End If
    End Sub
    Private Sub TXTTotalGrid_Leave(sender As System.Object, e As System.EventArgs) Handles TXTTotalGrid.Leave
        formatacampo()
    End Sub

    Private Sub TXTTotalGrid_TextChanged(sender As System.Object, e As System.EventArgs) Handles TXTTotalGrid.TextChanged
        formatacampo()
    End Sub

    Private Sub TXTTotalGrid_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles TXTTotalGrid.MouseUp
        TXTTotalGrid.SelectAll()
    End Sub
#End Region
#Region "Pre paint"
    Private Sub DGVDados_RowPrePaint(sender As System.Object, e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DGVDados.RowPrePaint
        Me.DGVDados.CurrentRow.Selected = False
        Try
            If DGVDados.Rows.Count > 0 Then
                If (DGVDados.Rows(e.RowIndex).Cells(13).Value = "Aberto") And (DGVDados.Rows(e.RowIndex).Cells(11).Value = Date.Now.ToShortDateString) Then
                    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Yellow 'hoje
                End If
                If (DGVDados.Rows(e.RowIndex).Cells(13).Value = "Aberto") And (DGVDados.Rows(e.RowIndex).Cells(11).Value > Date.Now.ToShortDateString) Then
                    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White 'não vencidas (futuro)
                End If
                If (DGVDados.Rows(e.RowIndex).Cells(13).Value = "Aberto") And (DGVDados.Rows(e.RowIndex).Cells(11).Value < Date.Now.ToShortDateString) Then
                    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Salmon 'vencidos
                End If
                If (DGVDados.Rows(e.RowIndex).Cells(13).Value = "Fechado") Then
                    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.PaleGreen 'fechados
                End If
                'Else
                '    DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White 'futuros
            End If
        Catch
        End Try
    End Sub
#End Region
End Class